package com.briup.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.briup.bean.Email;
import com.briup.bean.User;
import com.briup.util.EmailTool;
import com.briup.util.RandomNumTool;

@WebServlet("/RandomNumSer")
public class RandomNumSer extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	@SuppressWarnings("static-access")
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		HttpSession session=request.getSession();
		String email=(String) session.getAttribute("email");
		System.out.println(email);
		if(email==null) {
			
		}else {
		Email email1=new Email();
		User user=new User();
		RandomNumTool RandomNum=new RandomNumTool();
		String codeNum=RandomNum.getRandomNumCode(4);
		String content="您用于找回密码的验证码是："+codeNum+",打死也不能告诉别人！";
		user.setEmail(email);
		email1.setTitle("找回密码的验证码！");
		email1.setContent(content);
		EmailTool.sendEmail(email1, user);
		session.setAttribute("codeNum", codeNum);
		//response.sendRedirect("forgetPassword1.jsp");
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		
	}

}
